#!/usr/bin/perl -w
use Tk;
use Tk::Animation;
require Tk::PNG;
$mw = new MainWindow;
$mw -> geometry ("730x730");


$frm = $mw ->Frame()->pack;

$particle_gif ="/home/qtedq/cs277/hapticuda/particle.gif";
$particle_animate = $mw->Animation(-format => 'gif', -file => $particle_gif);
$nbody_gif ="/home/qtedq/cs277/hapticuda/nbody.gif";
$nbody_animate =    $mw->Animation(-format => 'gif', -file => $nbody_gif);
$fluid_gif ="/home/qtedq/cs277/hapticuda/fluid.gif";
$fluid_animate =    $mw->Animation(-format => 'gif', -file => $fluid_gif);

$particle_animate->start_animation(100);
$nbody_animate->start_animation(100);
$fluid_animate->start_animation(100);

$p_button = $frm->Button(-image => $particle_animate, -command=>\&start_particle);
$n_button = $frm->Button(-image => $nbody_animate, -command => \&start_nbody); 
$f_button = $frm->Button(-image => $fluid_animate, -command => \&start_fluid);

$splash = $mw->Photo(-format => 'png', -file => "/home/qtedq/cs277/hapticuda/splash.png");
$i_label = $frm->Label(-image => $splash);

$p_button->grid($n_button);
$f_button->grid($i_label);


MainLoop;

sub start_particle{
    chdir "particle";
    run_stuff("./particle");
    chdir "..";
}

sub start_nbody{
    chdir "nbody";
    run_stuff("./nbody");
    chdir "..";
}

sub start_fluid{
    chdir "fluid";
    run_stuff("./fluid");
    chdir "..";
}


sub run_stuff{
    $particle_animate->stop_animation;
    $nbody_animate->stop_animation;
    $fluid_animate->stop_animation;
    $mw->iconify();

    system($_[0]);

    $mw->deiconify();
    $particle_animate->start_animation(100);
    $nbody_animate->start_animation(100);
    $fluid_animate->start_animation(100);
}
